package com.lemon.myproject.controller;

import com.lemon.myproject.exception.BizException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
*
* @Classname MyController
* @Description MyController
* @Date 2023/4/23 10:11
* @Author PC
*/
@Controller
public class MyController {

    @PostMapping("/add")
    @ResponseBody
    public String add(@RequestBody User user) {
        //如果姓名为空就手动抛出一个自定义的异常！
        if(user.getName()==null){
            throw  new BizException("-1","用户姓名不能为空！");
        }
        return user.getName();
    }

}
